/* ****************************************************************************
 *
 * Copyright (c) Microsoft Corporation. 
 *
 * This source code is subject to terms and conditions of the Microsoft Public License. A 
 * copy of the license can be found in the License.html file at the root of this distribution. If 
 * you cannot locate the  Microsoft Public License, please send an email to 
 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Microsoft Public License.
 *
 * You must not remove this notice, or any other, from this software.
 *
 * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
 * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
 * PARTICULAR PURPOSE.
 * ***************************************************************************/


#if !defined(AFX_PGLSCATTER_H__5CC89D7A_2FEA_469D_B8F3_7C288282E834__INCLUDED_)
#define AFX_PGLSCATTER_H__5CC89D7A_2FEA_469D_B8F3_7C288282E834__INCLUDED_

#if _MSC_lER > 1000
#pragma once
#endif // _MSC_lER > 1000

#include <pgl/core/PGLObject.h>
#include <pgl/core/PGLText.h>
#include <pgl/core/PGLData.h>

/*! 
	\defgroup PGLMiscChartGroup Other charts and graphical objects: scatter, image, marker
	\ingroup PGLObjectGroup
*/

/*! \brief A scatter of points

  This object defines a scatter of points, each point is characterized by
  - x,y coordinates
  - a value

  The chart is characterized by
  - a minimum/maximum value for the values associated with the points,
  - a colorbar
  - a marker type (circle, square, triangle)
  - a marker width


  \image html scatterexplain.png "Description of a scatter chart"
  \ingroup PGLMiscChartGroup
*/
class PGLCORE_EXT_CLASS CPGLScatter : public CPGLObject  
{
PGL_DECLARE_DYNCREATE(CPGLScatter);
public:
    //! \name Constructor
    //@{
    //! default constructor
    CPGLScatter();
    //! copy constructor
    CPGLScatter(const CPGLScatter& s){*this = s;};
    //! assignement constructor
    CPGLScatter& operator=(const CPGLScatter& s);
    //! desctructor
	virtual ~CPGLScatter();
	//! Clean data
	void CleanData();
	//@}

	//! \name Extent computation
	//@{
	//! Extent computation
    virtual void GetUnionExtent(gfxinterface::CGfxInterface& gfx, CPGLRectD& rExtent);
    ///virtual function to override in derived classes
    virtual void UpdateExtent(gfxinterface::CGfxInterface& gfx);
	//@}
		
	//! \name GUI
	//@{
    //! adds the Line2D property page to the property dialog
//    virtual void AddPropertyPage(CPropertySheet* pPropSheet);
	//@}

	//! \name Marker
	//@{
	//! Marker type
	enum EMarkerType
	{
		//! square
		MarkerTypeSquare = 1,
		//! circle
		MarkerTypeCircle = 2,
		//! triangle
		MarkerTypeTriangle = 3,
		//! text
		MarkerTypeText=4
	};
	//! transform enum to string
	static LPCTSTR MarkerType2String(EMarkerType type);
	//! transform string to enum
	static EMarkerType String2MarkerType(LPCTSTR strType);
	//! sets marker type
	void SetMarkerType( EMarkerType eMarkerType)	{	m_eMarkerType = eMarkerType;};
	//! return marker type
	EMarkerType GetMarkerType() const				{	return m_eMarkerType;};
	//! double marker width
	double	GetMarkerWidth() const					{	return m_dMarkerWidth;};
	//! set marker width
	void SetMarkerWidth(double dMarkerWidth);
	//@}

	//!\name Text marker
	//@{
	//! reference to text object controlling the marker text
	CPGLText& GetMarkerText()						{	return m_textMarker;};
	//! reference to text object controlling the marker text, const
	const CPGLText& GetMarkerText()	const			{	return m_textMarker;};
	//! sets the marker text as szString
	void SetString(LPCTSTR szString)				{	m_textMarker.SetString(szString);};
	//! return the current marker string
	LPCTSTR GetString() const						{	return m_textMarker.GetString();};
	//@}

	//! \name Color map
	//@{
	//! Sets the color map, \sa EColorMap
	void SetColorMap(CPGLUtility::EColorMap eCM)	{	m_eColorMap = eCM;};
	//! returns the current color map
	CPGLUtility::EColorMap GetColorMap() const		{	return m_eColorMap;};
	//@}

	//!  \name Data manipulation
	//@{
	//! returns the number of valid points min(size vX, vY, vValues)
	size_t GetNPoints() const;
   //! Sets the datas
    void SetDatas(const std::vector<float>& vXs, const std::vector<float>& vYs, const std::vector<float>& vValues);
    //! Sets the datas
    void SetDatas(CPGLDataPtr pX, CPGLDataPtr pY, CPGLDataPtr pValues);
	//! returns Xs
	CPGLDataPtr GetXs()						{	return m_pX;};
	//! returns Xs, const
	const CPGLDataPtr GetXs() const			{	return m_pX;};
	//! returns Ys
	CPGLDataPtr GetYs()						{	return m_pY;};
	//! returns Ys, const
	const CPGLDataPtr GetYs() const			{	return m_pY;};
	//! returns Values
	CPGLDataPtr GetValues()					{	return m_pValues;};
	//! returns Values, const
	const CPGLDataPtr GetValues() const		{	return m_pValues;};
	//@}

	//! \name Data flushing
	//@{
	//! Sets data flushing (if true, point are deleted after being drawed)
	void SetDataFlushing(bool bFlusing = true)	{	m_bDataFlushing = bFlusing;};
	//! return data flushing state
	bool IsDataFlushing() const					{	return m_bDataFlushing;};
	//@}

	//! \name Value limits
	//@{
	//! returns actual minimul value
	double GetMinValue() const	{	return m_dMinValue;};
	//! returns actual max value
	double GetMaxValue() const	{	return m_dMaxValue;};
	//! Set min value
	void SetMinValue(double dMinValue)	{	m_dMinValue = dMinValue;};
	//! Set max value
	void SetMaxValue(double dMaxValue)	{	m_dMaxValue = dMaxValue;};
	//@}

	//! \name Plot method
	//@{
	//! Main plot function
	virtual void PlotGfx(gfxinterface::CGfxInterface& gfx);
	virtual void PlotLegendGfx(gfxinterface::CGfxInterface& gfx, const CPGLRectD& rBox);
	//@}

	//! \name Scripting methods
	//@{
	//! property enumeration
	enum EScatterProp
	{
		ScatterPropUnknow,
		ScatterPropMarkerType,
		ScatterPropMarkerWidth,
		ScatterPropMarkerString,
		ScatterPropColorMap,
		ScatterPropDataFlushing,
		ScatterPropMinValue,
		ScatterPropMaxValue
	};
	PGL_DECLARE_SCRIPTING(Scatter);
	//@}

	//! \name Serialization and debugging
	//@{
	//! Saving setttings to XML
	void SerializeXML(CPGLArchive& ar);
    //! Debuggin functions
    #ifdef _DEBUG
        virtual void Dump( CDumpContext& dc ) const;
        virtual void AssertValid() const;    // Override
    #endif
    //@}
protected:
		//! \name Protected attributes
	//@{
	//! x lists
	CPGLDataPtr m_pX;
	//! y lists
	CPGLDataPtr m_pY;
	//! values lists
	CPGLDataPtr m_pValues;
	//! data flushing state
	bool m_bDataFlushing;
	//! min value in color map
	double m_dMinValue;
	//! max value in color map,
	double m_dMaxValue;
	//! Marker width (pixels)
	double m_dMarkerWidth;
	//! marker type
	EMarkerType m_eMarkerType;
	//! marker text if of type MarkerTypeText
	CPGLText m_textMarker;
	//! color map
	CPGLUtility::EColorMap m_eColorMap;
	//@}
private:
	CPGLRectU m_rLimitIndices;
};

PGL_DECLARE_SMARTPTR( CPGLScatter );

/*! \example scatter.cpp

This example demonstrate the scatter chart.
\image html scatter.png "Scatter chart (array of points with coloring depending on a value"
*/
#endif // !defined(AFX_PGLSCATTER_H__5CC89D7A_2FEA_469D_B8F3_7C288282E834__INCLUDED_)
